package com.threaddemo6;

import java.util.concurrent.*;

public class NewFixedThreadPool1 {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        //固定长度的连接池
        ExecutorService es = Executors.newFixedThreadPool(3);

        //submit:将线程放到线程池中
        Future<String> f1 = es.submit(new Callable<String>() {
            @Override
            public String call() throws Exception {
                System.out.println("执行 f1 " + Thread.currentThread().getName());
                return "Hello F1";
            }
        });

        Future f2 = es.submit(new Runnable() {
            @Override
            public void run() {
                System.out.println("执行f2 = " + Thread.currentThread().getName());
            }
        });

        es.execute(new Runnable() {
            @Override
            public void run() {
                System.out.println("执行f3 = " + Thread.currentThread().getName());
            }
        });

        System.out.println("f1 = " + f1.get());
        System.out.println("f2 = " + f2.get());

        es.shutdown();

    }
}
